#ifndef _MAC_ARRAY_MESSAGE_BASE_HPP
#define _MAC_ARRAY_MESSAGE_BASE_HPP 1

#include <stdint.h>
#include <boost/shared_ptr.hpp>
#include "Digest.hpp"
#include "../constants.hpp"
#include "VerifiedMessageBase.hpp"

namespace BFT
{
	namespace messages
	{

		struct macArrayMessageStruct
		{
		  uint32_t sender;
		  uint32_t digest_start;
		  boost::shared_ptr<Digest> digest;
		  uint32_t macarray_start;
		  uint32_t macarray_size; //number of macs in macarray
		};


		class MacArrayMessage : public VerifiedMessageBase
		{

		public:

		  MacArrayMessage(uint16_t _tag, uint32_t _size, uint32_t _sender, uint32_t _arraySize);

		  MacArrayMessage(boost::shared_ptr<char> _bits, int _buffer_length);

		  MacArrayMessage(VerifiedMessageBase vmb);

		  uint32_t computeAuthenticationSize(uint32_t _arraySize); // size is expressed in number of MACs within the MAC array

		  uint32_t getSender();
		  
		  uint32_t getDigestStartIndex();
		  
		  boost::shared_ptr<Digest> getAuthenticationDigest();

		  bool checkAuthenticationDigest();
		  
		  uint32_t getMacarrayStartIndex();
		  
		  uint32_t getMacarraySize();
		  
		//  void getMacAt(mac_t& _mac, int index);
		  
		  boost::shared_ptr<char> getMacArray(int& _macs_number);

		  bool isValid();

		  void printInfo();

		  void setMacBytes();	

		protected:

		  macArrayMessageStruct info;
		  MacArrayMessage();
		  
		};


		inline uint32_t MacArrayMessage::computeAuthenticationSize(uint32_t _arraySize) { return (_arraySize*MAC_SIZE + DIGEST_SIZE + SENDER_SIZE); }

		inline uint32_t MacArrayMessage::getSender() {return info.sender;}

		inline uint32_t MacArrayMessage::getDigestStartIndex() {return info.digest_start;}

		//inline void MacArrayMessage::getDigest(digest_t& _digest) {memcpy((void*)_digest,(const void*)info.digest, sizeof(char)*DIGEST_SIZE);}

		inline uint32_t MacArrayMessage::getMacarrayStartIndex() {return info.macarray_start;}

		inline uint32_t MacArrayMessage::getMacarraySize() {return info.macarray_size;} 


	} //namespace messages
} // namespace BFT


#endif
